package com.lz.d;

/**
 * @ClassName Demo39
 * @Description while循环练习
 * @Author 2214361854
 * @Date 2022/5/27 16:46
 * @Version 1.0
 */
public class Demo39 {
    /**
     * 需求1:通过while循环打印10次"小可爱们中午好~"
     * 需求2:通过while循环打印1 2 3 ... 10
     * 需求3:通过while循环打印1 3 5 7 9 ... 99
     * 需求4:通过while计算:1+2+3+4+...+10
     * 需求5:通过while计算:2+4+6+8...+100
     */
    public static void main(String[] args) {
        f1();
        f2();
        f3();
        f4();
        f5();
    }

    private static void f1() {
        int i = 1;
        while (i <= 10) {
            System.out.println(i);
            i++;
        }
    }

    private static void f2() {
        int i = 1;
        while (i <= 10) {
            System.out.print(i + " ");
            i++;
        }
    }

    private static void f3() {
        int i = 1;
        while (i <= 100) {
            if (i % 2 != 0) {
                System.out.print(i + " ");
            }
            i++;
        }
    }

    private static void f4() {
        int sum = 0;
        int i = 1;
        while (i <= 10) {
            sum += i;
            i++;
        }
        System.out.println(sum);
    }

    private static void f5() {
        int sum = 0;
        int i = 1;
        while (i <= 100) {
            if (i % 2 == 0) {
                sum += i;
            }
            i++;
        }
        System.out.print(sum);
    }
}
